package com.lxq.test1812.Main01;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r,y,g;
        r=sc.nextInt();
        y=sc.nextInt();
        g=sc.nextInt();

        int n=sc.nextInt();
        int sumTime = 0;
        for (int i=0;i<n;i++){
            int type=sc.nextInt();
            int time=sc.nextInt();
            switch (type) {
                case 0:sumTime = sumTime + time;break;
                case 1:sumTime = sumTime + time;break;
                case 2:sumTime = sumTime + time + r;break;
                case 3:break;
            }
        }
        System.out.println(sumTime);
    }
}
